package com.wnhz.work.jy.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.jy.MyApplication;
import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.CommentsBean;
import com.wnhz.work.jy.bean.EvaluateBean;

import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2016/9/7 0007.
 */
public class EvaluateAdapter extends BaseAdapter {
    private Context context;
    private List<CommentsBean> evaluateList;

    public EvaluateAdapter(Context context, List<CommentsBean> evaluateList) {
        this.context = context;
        this.evaluateList = evaluateList;
    }

    @Override
    public int getCount() {
        return evaluateList.size();
    }

    @Override
    public Object getItem(int position) {
        return evaluateList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        EvaluateViewHolder viewHolder = new EvaluateViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.evaluate_item, null);
            viewHolder.recyclerView = (RecyclerView) convertView.findViewById(R.id.recyclerView);
            viewHolder.iv_head = (ImageView) convertView.findViewById(R.id.iv_head);//头像
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);//姓名
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);//时间
            viewHolder.tv_content = (TextView) convertView.findViewById(R.id.tv_content);//内容

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (EvaluateViewHolder) convertView.getTag();
        }

        // 用于显示的加*用户名
        String getName = evaluateList.get(position).getName();
        String name = getName.substring(0, 1) + "****" + getName.substring(getName.length() - 1);

//        ImageLoader.getInstance().displayImage(String.valueOf(evaluateList.get(position).getHead()), viewHolder.iv_head);
        x.image().bind(viewHolder.iv_head,evaluateList.get(position).getTouimg(), MyApplication.getInstance().headoptions);
        viewHolder.tv_name.setText(name);
        viewHolder.tv_time.setText(evaluateList.get(position).getAddtime());
        viewHolder.tv_content.setText(evaluateList.get(position).getContent());

        LinearLayoutManager manager = new LinearLayoutManager(context);
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        viewHolder.recyclerView.setLayoutManager(manager);
        MapRecyclerViewAdapter adapter = new MapRecyclerViewAdapter(context, evaluateList.get(position).getPhoto(), new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        viewHolder.recyclerView.setAdapter(adapter);
        if (evaluateList.get(position).getPhoto().size() == 0){
            viewHolder.recyclerView.setVisibility(View.GONE);
        }else {
            viewHolder.recyclerView.setVisibility(View.VISIBLE);
        }
        return convertView;
    }

    class EvaluateViewHolder {
        ImageView iv_head;
        TextView tv_name;
        TextView tv_time;
        TextView tv_content;
        RecyclerView recyclerView;
    }
}
